package info.matsumana.sandbox;

import com.mysql.fabric.jdbc.FabricMySQLConnection;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @author matsumana
 */
public abstract class DatabaseAccess {

    static FabricMySQLConnection getConnection() throws Exception {
        String hostname = "192.168.1.117";
        String port = "32274";
        String database = "fabric_test";
        String user = "root";
        String password = "111111";

        String baseUrl = "jdbc:mysql:fabric://" + hostname + ":" + Integer.valueOf(port) + "/";
        // Load the driver if running under Java 5
        if (!com.mysql.jdbc.Util.isJdbc4()) {
            Class.forName("com.mysql.fabric.jdbc.FabricMySQLDriver");
            System.out.println("load driver");
        }

        Connection rawConnection = DriverManager.getConnection(baseUrl + database + "?fabricShardTable=b", user, password);
        return (FabricMySQLConnection) rawConnection;
    }
}
